package org.mili.ticketeer.dto;

import org.mili.application.dto.Archivable;
import org.mili.application.dto.Field;
import org.mili.application.dto.Identifieable;

import java.util.HashMap;
import java.util.Map;

public class Contact extends Identifieable implements Archivable {

    public static enum Fields implements Field {
        FIRSTNAME,
        LASTNAME,
        STREET,
        NUMBER,
        ZIP,
        SEX,
        PHONE,
        EMAIL,
        TOKEN,
        ACTIVE,
        ISSPEAKER;
    }

    public static enum UniqueFields implements Field {
        FIRSTNAME,
        LASTNAME;
    }

    public static final String TABLE = "contact";

    private String firstName;
    private String lastName;
    private String street;
    private String number;
    private int zip;
    private SexEnum sex;
    private String phone;
    private String email;
    private String token;
    private boolean active;
    private boolean speaker;

    @Override
    public Map<Field, Object> valueMap() {
        Map<Field, Object> map = super.valueMap();
        map.put(Fields.FIRSTNAME, firstName);
        map.put(Fields.LASTNAME, lastName);
        map.put(Fields.STREET, street);
        map.put(Fields.NUMBER, number);
        map.put(Fields.ZIP, zip);
        map.put(Fields.SEX, sex.getCode());
        map.put(Fields.PHONE, phone);
        map.put(Fields.EMAIL, email);
        map.put(Fields.TOKEN, token);
        map.put(Fields.ACTIVE, active);
        map.put(Fields.ISSPEAKER, speaker);
        return map;
    }

    @Override
    public Map<Field, Object> valueMapWithoutId() {
        Map<Field, Object> map = new HashMap<>(valueMap());
        map.remove(Identifieable.Fields.ID);
        return map;
    }

    @Override
    public Map<Field, Object> getUniqueFields() {
        Map<Field, Object> map = new HashMap<>();
        map.put(Fields.FIRSTNAME, firstName);
        map.put(Fields.LASTNAME, lastName);
        return map;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public int getZip() {
        return zip;
    }

    public void setZip(int zip) {
        this.zip = zip;
    }

    public SexEnum getSex() {
        return sex;
    }

    public void setSex(SexEnum sex) {
        this.sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean isSpeaker() {
        return speaker;
    }

    public void setSpeaker(boolean speaker) {
        this.speaker = speaker;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Contact contact = (Contact) o;

        if (active != contact.active) return false;
        if (speaker != contact.speaker) return false;
        if (zip != contact.zip) return false;
        if (email != null ? !email.equals(contact.email) : contact.email != null) return false;
        if (firstName != null ? !firstName.equals(contact.firstName) : contact.firstName != null) return false;
        if (lastName != null ? !lastName.equals(contact.lastName) : contact.lastName != null) return false;
        if (number != null ? !number.equals(contact.number) : contact.number != null) return false;
        if (phone != null ? !phone.equals(contact.phone) : contact.phone != null) return false;
        if (sex != contact.sex) return false;
        if (street != null ? !street.equals(contact.street) : contact.street != null) return false;
        if (token != null ? !token.equals(contact.token) : contact.token != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = firstName != null ? firstName.hashCode() : 0;
        result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
        result = 31 * result + (street != null ? street.hashCode() : 0);
        result = 31 * result + (number != null ? number.hashCode() : 0);
        result = 31 * result + zip;
        result = 31 * result + (sex != null ? sex.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (token != null ? token.hashCode() : 0);
        result = 31 * result + (active ? 1 : 0);
        result = 31 * result + (speaker ? 1 : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Contact{" +
                "firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", street='" + street + '\'' +
                ", number='" + number + '\'' +
                ", zip=" + zip +
                ", sex=" + sex +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", token='" + token + '\'' +
                ", active=" + active +
                ", speaker=" + speaker +
                '}';
    }
}
